{include "Public/header"}
	<div class="page_tit">{$title}</div>
	<!-- START CONFIG_FORM -->
	<form method="POST" action="">
	{if isset($_GET['id'])}
	<input type="hidden" name="id" value="{:intval($_GET['id'])}" />
	{/if}
		<div class="form2">
			<dl class="lineD">
				<dt>
					<font color="red">*</font>所属品牌：
				</dt>
				<dd>
					<select name="car_id">
					{foreach $car_list as $v}
					<option value="{$v['id']}" {if isset($info)&&$info['car_id']==$v['id']}selected{/if}>{$v['name']}</option>
					{/foreach}
					</select>
				</dd>
			</dl>
			<dl class="lineD">
				<dt>
					<font color="red">*</font>所属车型：
				</dt>
				<dd>
					<select name="model_id">
					</select>
				</dd>
			</dl>
			<dl class="lineD">
				<dt>
					<font color="red">*</font>排量：
				</dt>
				<dd>
					<input name="name" maxlength="255" type="text" value="{$info['name']|''}" class="s-big-txt">
				</dd>
			</dl>
			<dl class="lineD">
				<dt>
					<font color="red">*</font>排序：
				</dt>
				<dd>
					<input name="sort" maxlength="5" type="text" value="{$info['sort']|'50'}" class="small-s-txt">
					<font color="red">*</font>排序按照升序进行排列
				</dd>
			</dl>
			<dl class="lineD">
				<dt>
					&nbsp;
				</dt>
				<dd>
					<a href="#" id="add-project">新增关联项目</a>
				</dd>
			</dl>
			{if isset($info['displacement_project_list'])&&!empty($info['displacement_project_list'])}
			{foreach $info['displacement_project_list'] as $v}
			<dl class="lineD">
				<dt>
					&nbsp;
				</dt>
				<dd>
					项目  <select name="project_id[]">
{foreach $project_list as $item}
<option value="{$item['id']}" {if $v['project_id']==$item['id']}selected{/if}>{$item['name']}</option>
{/foreach}
</select> 
					项目价格 <input name="price[]" maxlength="5" type="number" value="{$v['price']}" class="small-s-txt">元
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="delete-project">删除</a>
				</dd>
			</dl>
			{/foreach}
			{/if}
			<div class="page_btm">
				<input type="submit" class="btn_b" value="保存"  />
			</div>
		</div>
	</form>
	<!-- END CONFIG_FORM -->
</div>
<script src="__CONTENT__/js/baiduTemplate.js"></script>
<script type="text/javascript">
$(function(){
	var model_list={$model_list};
	$("select[name='car_id']").change(function(){
		var car_id=$(this).val();
		var default_model_id={:isset($info)?$info['model_id']:'0'};
		var html='';
		for(var i in model_list[car_id]){
			html+='<option value="'+model_list[car_id][i].id+'"';
			if(default_model_id==model_list[car_id][i].id){
				html+=' selected ';
			}
			html+='>'+model_list[car_id][i].name+'</option>';
		}
		$("select[name='model_id']").html(html);
	});
	$("select[name='car_id']").change();
	$("form").validate({
		rules : {
			name: {
				required : true,
				rangelength : [ 1, 255]
			},
			sort : {
				required:true,
				digits : true
			}
		},
		messages:{
			name:{
				required:"排量必须填写",
				rangelength:"排量必须在1-255个字之间"
			},
			sort:{
				required:"排序必须填写",
				digits:"排序必须为数字"
			}
		}
	});
	$("#add-project").click(function(){
		$(this).parents(".lineD").after(baidu.template("add-project-html",{}));
		return false;
	});
	$(document).on("click",".delete-project",function(){
		$(this).parents(".lineD").remove();
		return false;
	});
});
</script>
<script type="text/html" id="add-project-html">
<dl class="lineD">
				<dt>
					&nbsp;
				</dt>
				<dd>
					项目 <select name="project_id[]">
{foreach $project_list as $v}
<option value="{$v['id']}">{$v['name']}</option>
{/foreach}
</select> 
					项目价格 <input name="price[]" maxlength="5" type="number" value="0" class="small-s-txt">元
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="delete-project">删除</a>
				</dd>
			</dl>
</script>
</html>